<template>
  <div class="article-management">
    <div class="header">
      <h1 style="display: inline-block">文章管理</h1>
      <el-button style="margin-left: 3rem" type="primary">写文章</el-button>
    </div>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="limit"
        layout="prev, pager, next"
        :total="total">
      </el-pagination>
    </div>

    <el-table :data="articles" width="100%" stripe>
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="title" label="标题" ></el-table-column>
      <el-table-column prop="class" label="分类" width="150"></el-table-column>
      <el-table-column prop="tag" label="标签" width="150" ></el-table-column>
      <el-table-column prop="gmtCreate" label="创建日期" ></el-table-column>
      <el-table-column label="操作" align="right">
        <template slot="header" slot-scope="
// eslint-disable-next-line vue/no-unused-vars
        scope">
          <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
        </template>
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="limit"
        layout="prev, pager, next"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
export default {
  name: 'ArticleManagement',
  data () {
    return {
      articles: [],
      start: 0,
      limit: 15,
      total: 0,
      searchKeyword: ''
    }
  },
  methods: {
    load () {
      this.articles = [
        {
          title: 's',
          class: 's',
          tag: 's',
          gmtCreate: '2018-3-5 19:24:27'
        },
        {
          title: 'Hello,world!',
          class: 'c',
          tag: 't',
          gmtCreate: '2020-6-5 21:34:15'
        }
      ]
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange (val) {
      this.start = this.limit * (val - 1) // val 页面
      this.load()
    }
  },
  beforeMount () {
    this.load()
  }
}
</script>

<style scoped>

</style>
